<template>
  <div class="home">
    <el-card shadow="always">
      <el-form ref="form" :model="form" :rules="fromrule" label-width="100px" style="height: 100%"
               label-position="right" @keyup.native.enter="onSubmit()"
               size="mini">
        <el-form-item>
          <span slot="label">
      	     <span style="color: black"><strong>事件类型:</strong></span>
           </span>
          <el-select v-model="form.region" placeholder="请选择" @change="changeShijian">
            <el-option label="泄漏风险" value="leak"></el-option>
            <el-option label="漏洞风险" value="loophole"></el-option>
            <el-option label="网站风险" value="website"></el-option>
            <el-option label="API事件" value="API"></el-option>
            <el-option label="账号事件" value="Account"></el-option>
            <el-option label="客户端事件" value="client"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="name">
          <span slot="label">
      	     <span style="color: black"><strong>服务域名:</strong></span>
           </span>
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item prop="Authorization" v-if="['leak','loophole','website'].includes(form.region)">
          <span slot="label">
      	     <span style="color: black"><strong>请 求 头:</strong></span>
           </span>
          <el-input v-model="form.Authorization"></el-input>
        </el-form-item>

        <el-form-item prop="canshu">
           <span slot="label">
      	     <span style="color: black"><strong>请求参数:</strong></span>
           </span>
          <el-input type="textarea" v-model="form.canshu" autosize></el-input>
        </el-form-item>

        <el-form-item style="text-align: center">
         <span slot="label">
      	     <span style="color: black"><strong>发送次数:</strong></span>
           </span>
          <template slot-scope="scop">
            <el-input-number v-model="form.sum" :min="1" :max="20"
                             label="描述文字"></el-input-number>
            <el-button type="primary" @click="onSubmit">立即执行</el-button>
          </template>
        </el-form-item>

      </el-form>
      <el-table id='tables' :data="tableData" height="450px" border style="width: 100%">
        <el-table-column prop="date" label="日期" width="140"></el-table-column>
        <el-table-column prop="lablename" label="事件类型" width="100"></el-table-column>
        <el-table-column label="域名" width="180">
          <template slot-scope="scope">
            <el-popover placement="top-start" trigger="hover">
              <div>{{ scope.row.name }}</div>
              <span slot="reference"
                    style="text-overflow: ellipsis;overflow: hidden;white-space: nowrap;">{{ scope.row.name }}</span>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column prop="Authorization" label="请求头" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column label="参数" style="width: 30%;">
          <template slot-scope="scope">
            <el-popover placement="top-start" width="500" trigger="hover">
              <json-viewer
                  :value="scope.row.canshu"
                  :expand-depth=5
                  boxed
                  sort
                  copyable
                  :expanded=expanded
                  :key="expanded"
              >
                <template v-slot:copy="{copied}">
                  <span v-if="copied">复制成功</span>
                  <span v-else>复制</span>
                  <div>
                    <a-button style="position: absolute; left:50%;transform: translate(-50%)" type="primary"
                              @click="toggleExpanded">{{ expanded ? '收起' : '展开' }}
                    </a-button>
                  </div>
                </template>
              </json-viewer>
              <span slot="reference"
                    style="text-overflow: ellipsis;overflow: hidden;white-space: nowrap;">{{ scope.row.canshu }}</span>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column prop="sum" label="次数" width="50"></el-table-column>
        <el-table-column label="结果">
          <template slot-scope="scope">
            <el-popover placement="top-start" width="500" trigger="hover">
              <!--              <div>{{ scope.data.copyable}}</div> "scope.row.canshu" :copyable="copyable"-->
              <json-viewer
                  :value="scope.row.res"
                  :expand-depth=5
                  boxed
                  sort
                  copyable
                  :expanded=resexpanded
                  :key="resexpanded"
              >
                <template v-slot:copy="{copied}">
                  <div>
                    <a-button style="position: absolute; left:50%;transform: translate(-50%)" type="primary"
                              @click="restoggleExpanded">{{ resexpanded ? '收起' : '展开' }}
                    </a-button>
                  </div>
                </template>
              </json-viewer>
              <span slot="reference"
                    style="text-overflow: ellipsis;overflow: hidden;white-space: nowrap;">{{ scope.row.canshu }}</span>
            </el-popover>
          </template>

        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scop">
            <el-button type="primary"
                       @click="onRun(scop.row)"
                       size="mini">执行
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
// @ is an alias to /src
import {addDataInfo, getDataInfo} from '@/api/data/makedata'

export default {

  name: 'Home',
  components: {},

  data() {
    var checkcanshu = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('参数不能为空'));
      }
      try {
        JSON.parse(value) // 如果不是json字符串就会抛异常
        callback();
      } catch (e) {
        callback(new Error('请输入json参数'));
      }
    };
    return {
      expanded: false,
      resexpanded: false,
      copyable: {copyText: '复制', copiedText: '已复制', timeout: 2000},
      defaultRegion: 'leak',
      defaultInfo: {
        leak: {
          host: 'http://10.50.3.106:8085/platform/dataBreach',
          canshu: '{\n' +
              '    "classify":[\n' +
              '        "敏感数据"\n' +
              '    ],\n' +
              '    "issueName":"弱口令1",\n' +
              '    "riskLevel":"0",\n' +
              '    "dbType":"My版本SQL",\n' +
              '    "issueIP":"10.50.3.136",\n' +
              '    "issuePort":9200,\n' +
              '    "riskHistory":"{\\"riskHistory\\":[{\\"riskTime\\":\\"2022-11-2815:15:49\\",\\"riskUpdateDesc\\":\\"首次发生时间\\"},{\\"riskTime\\":\\"2022-11-2815:15:49\\",\\"riskUpdateDesc\\":\\"更新验证时间\\"}]}",\n' +
              '    "evidenceInfo":"{\\"evidenceInfo\\":[\\"425\\",\\"427\\",\\"421\\",\\"422\\",\\"447\\",\\"446\\",\\"448\\",\\"468\\",\\"472\\",\\"428\\",\\"436\\",\\"441\\",\\"453\\",\\"463\\",\\"465\\",\\"469\\",\\"461\\",\\"479\\",\\"493\\",\\"449\\",\\"489\\",\\"474\\",\\"498\\",\\"481\\",\\"487\\",\\"497\\",\\"413\\",\\"431\\",\\"409\\",\\"426\\"]}",\n' +
              '    "issueSolution":"1、目前厂商已发布升级补丁以修复漏洞，补丁获取链接：\\nhttps://www.cybersecurity-help.cz/vdb/SB2022011905",\n' +
              '    "lawInfo":"{\\"lawInfo\\":[{\\"title\\":\\"中华人民共和国数据安全法\\",\\"content\\":\\"第四十五条　开展数据处理活动的组织、个人不履行本法第二十七条、第二十九条、第三十条规定的数据安全保护义务的，由有关主管部门责令改正，给予警告，可以并处五万元以上五十万元以下罚款，对直接负责的主管人员和其他直接责任人员可以处一万元以上十万元以下罚款；拒不改正或者造成大量数据泄露等严重后果的，处五十万元以上二百万元以下罚款，并可以责令暂停相关业务、停业整顿、吊销相关业务许可证或者吊销营业执照，对直接负责的主管人员和其他直接责任人员处五万元以上二十万元以下罚款。\\"}]}",\n' +
              '    "discoverFactory":"安恒信息",\n' +
              '    "eventFrom":"数据暴露面监测平台",\n' +
              '    "probeIp":"192.168.1.1",\n' +
              '    "operationMark":"新增",\n' +
              '    "dataFrom":"数据暴露面监测平台"\n' +
              '}'
        },
        loophole: {
          host: 'http://10.50.3.106:8085/platform/databaseVulnerability',
          canshu: '{\n' +
              '    "riskLevel":"4",\n' +
              '    "dbType":"MySQL",\n' +
              '    "riskHistory":"{\\"riskHistory\\":[{\\"riskTime\\":\\"2022-11-2114:59:13\\",\\"riskUpdateDesc\\":\\"首次发生时间\\"},{\\"riskTime\\":\\"2022-11-2114:59:13\\",\\"riskUpdateDesc\\":\\"更新验证时间\\"}]}",\n' +
              '    "lawInfo":"{\\"lawInfo\\":[{\\"title\\":\\"中华人民共和国数据安全法\\",\\"content\\":\\"第四十五条　开展数据处理活动的组织、个人不履行本法第二十七条、第二十九条、第三十条规定的数据安全保护义务的，由有关主管部门责令改正，给予警告，可以并处五万元以上五十万元以下罚款，对直接负责的主管人员和其他直接责任人员可以处一万元以上十万元以下罚款；拒不改正或者造成大量数据泄露等严重后果的，处五十万元以上二百万元以下罚款，并可以责令暂停相关业务、停业整顿、吊销相关业务许可证或者吊销营业执照，对直接负责的主管人员和其他直接责任人员处五万元以上二十万元以下罚款。\\"}]}",\n' +
              '    "operationMark":"新增",\n' +
              '    "affectLevel":"存在漏洞隐患",\n' +
              '    "issuePriorityModel":"{\\"priorityModel\\":{\\"assetImportance\\":0.0,\\"riskLevel\\":0.0,\\"disclosureTime\\":0.0,\\"vulComplexity\\":0.0,\\"vulImpactResult\\":0.0,\\"internetExpose\\":0.0}}",\n' +
              '    "issueAc":"4.4",\n' +
              '    "issueResult":"1",\n' +
              '    "@timestamp":"1669014266362",\n' +
              '    "issueIP":"2.2.2.2",\n' +
              '    "issuePort":11,\n' +
              '    "classify":[\n' +
              '        "数据库漏洞"\n' +
              '    ],\n' +
              '    "issueName":"OracleMySQL输入验证错误漏洞(CVE-2022-21444)",\n' +
              '    "issueDescription":"OracleMySQL是美国甲骨文（Oracle）公司的一套开源的关系数据库管理系统。MySQLServer是其中的一个数据库服务器组件。MySQLConnectors是其中的一个连接使用MySQL的应用程序的驱动程序。\\nOracleMySQL的MySQL服务器产品中存在输入验证错误漏洞，该漏洞允许通过多种协议进行网络访问的高权限攻击者破坏MySQL服务器。成功攻击此漏洞可能导致未经授权的能力导致MySQLServer挂起或频繁重复崩溃（完全DOS）。",\n' +
              '    "issueSolution":"目前厂商已发布升级补丁以修复漏洞，补丁获取链接：\\nhttps://www.oracle.com/security-alerts/cpuapr2022.html",\n' +
              '    "issueLevel":2,\n' +
              '    "cve":"CVE-2022-21444",\n' +
              '    "cnvd":"",\n' +
              '    "cvss":"4.4",\n' +
              '    "discoverFactory":"安恒信息",\n' +
              '    "issuePoc":"Installedversion:5.7.25Fixedversion:5.7.38\\nInstallation\\npath/port:2881/tcp",\n' +
              '    "eventFrom":"数据暴露面监测平台",\n' +
              '    "probeIp":"192.168.1.1",\n' +
              '    "dataFrom":"数据暴露面监测平台"\n' +
              '}'
        },
        website: {
          host: 'http://10.50.3.106:8085/platform/networkLeakage',
          canshu: '{\n' +
              '    "classify":[\n' +
              '        "主机漏洞"\n' +
              '    ],\n' +
              '    "issueName":"OracleWebLogicServer远程安全漏洞(CVE-2017-10063)",\n' +
              '    "riskLevel":"4",\n' +
              '    "riskDetail":"个人信息条数：9W条重要信息条数：1W条共占存储空间：10GB涉及数据库信息表：100个",\n' +
              '    "issueIP":"2.2.2.2",\n' +
              '    "issuePort":11,\n' +
              '    "riskHistory":"{\\"riskHistory\\":[{\\"riskTime\\":\\"2022-08-1217:23:39\\",\\"riskUpdateDesc\\":\\"首次发生时间\\"},{\\"riskTime\\":\\"2022-09-1217:23:39\\",\\"riskUpdateDesc\\":\\"验证更新时间\\"}]}",\n' +
              '    "dataSample":"链接成都市代理记账行业协会中国注册税务师协会中国注册会计师环境2020-06-28《中国会计报》报道我协会志愿者风采\\n国家外汇管理局数字外管平台中国电子口岸商务麽业务系统统一平\\n税人助力提升义乌营商环境《中国会计报》报道我协会志愿者风采\\n行业协会中国注册税务师协会中国注册会计师协会浙江省注册会计，联系人：王芳，电话：13291232310，邮箱：1241@163.com",\n' +
              '    "issueUrl":"http://data.zjzwfw.gov.cn/jdop_front/index.do",\n' +
              '    "sensitiveInformation":"身份证号",\n' +
              '    "checkMethod":"个人敏感信息",\n' +
              '    "issueSolution":"厂商补丁:\\nOracle\\n------\\nOracle已经为此发布了一个安全公告（cpujul2017-3236622）以及相应补丁:\\ncpujul2017-3236622：OracleCriticalPatchUpdateAdvisory-July2017\\n链接：http://www.oracle.com/technetwork/security-advisory/cpujul2017-3236622.html\\n\\n",\n' +
              '    "lawInfo":"{\\"lawInfo\\":[{\\"title\\":\\"《中华人民共和国数据安全法》\\",\\"content\\":\\"第四十五条.....\\"},{\\"title\\":\\"《中华人民共和国数据安全法》\\",\\"content\\":\\"第四十五条.....\\"},{\\"title\\":\\"《中华人民共和国数据安全法》\\",\\"content\\":\\"第四十五条.....\\"}]}",\n' +
              '    "discoverFactory":"安恒信息",\n' +
              '    "eventFrom":"数据暴露面监测平台",\n' +
              '    "probeIp":"192.168.1.2",\n' +
              '    "operationMark":"新增",\n' +
              '    "dataFrom":"数据暴露面监测平台"\n' +
              '}'
        },
        API: {
          host: 'https://10.50.2.174/open/api/v1/ds/addSecurityEvent/dataBreach',
          canshu: '{\n' +
              '    "eventFrom":"AIDLP",\n' +
              '    "discoverFactory":"安恒信息",\n' +
              '    "eventsType":[\n' +
              '        "rge合法化文sdcs"\n' +
              '    ],\n' +
              '    "eventsThreatSeverity":"bigEvent",\n' +
              '    "attacker":[\n' +
              '        "192.168.36.1"\n' +
              '    ],\n' +
              '    "attackPort":"6080",\n' +
              '    "victim":[\n' +
              '        "2.2.2.2"\n' +
              '    ],\n' +
              '    "destPort":11,\n' +
              '    "transportProtocol":"http",\n' +
              '    "appProtocol":[\n' +
              '        "http"\n' +
              '    ],\n' +
              '    "ruleId":"1002000000000000008",\n' +
              '    "requestBody":"ferf",\n' +
              '    "requestDomain":"10.10.10.1:8888",\n' +
              '    "requestMethod":"POST",\n' +
              '    "clientInfo":"PostmanRuntime/7.29.2",\n' +
              '    "appPotocolVersion":"2.23.1",\n' +
              '    "requestUrl":"/TESt1/ajsnDAS/00001",\n' +
              '    "requestUrlQuery":"192.168.36.163:8088/tesTS1",\n' +
              '    "httpQuote":"192.168.36.163:8088",\n' +
              '    "responseCode":"200",\n' +
              '    "responseMsg":"{\\"code\\":\\"200\\"}",\n' +
              '    "sensitiveDataCount":"2",\n' +
              '    "evidence":"949018974859697139",\n' +
              '    "probeIp":"10.20.48.30",\n' +
              '    "dataFrom":"dscApiSecurity",\n' +
              '    "sensitiveType":"机密/涉密"\n' +
              '}'
        },
        Account: {
          host: 'https://10.50.2.174/open/api/v1/ds/addSecurityEvent/accountSecurity',
          canshu: '{\n' +
              '    "eventFrom":"AIDLP",\n' +
              '    "discoverFactory":"安恒信息",\n' +
              '    "eventsType":[\n' +
              '        "账号非工作时间获取数据主体超100条"\n' +
              '    ],\n' +
              '    "eventsThreatSeverity":"commonEvent",\n' +
              '    "attacker":[\n' +
              '        "192.168.36.1"\n' +
              '    ],\n' +
              '    "victim":[\n' +
              '        "2.2.2.2"\n' +
              '    ],\n' +
              '    "destPort":11,\n' +
              '    "transportProtocol":"http",\n' +
              '    "appProtocol":[\n' +
              '        "http"\n' +
              '    ],\n' +
              '    "ruleId":"1002000000000000011",\n' +
              '    "requestBody":"{“input1”:”xxx”,”input2”:”ooo”,”remember”:false}",\n' +
              '    "requestDomain":"192.168.36.163:8088",\n' +
              '    "requestMethod":"POST",\n' +
              '    "clientInfo":"PostmanRuntime/7.29.2",\n' +
              '    "appPotocolVersion":"7.29.2\\r\\nAccept:*/*\\r\\nPostman-Token:3955239a-a295-4408-b534-c30b8005b803\\r\\nHost:192.168.36.163:8088\\r\\nReferer:192.168.36.163:8088\\r\\nAccept-Encoding:gzip,deflate,br\\r\\nConnection:keep-alive\\r\\nContent-Length:19270",\n' +
              '    "requestUrl":"/test1/ajsndas/00001",\n' +
              '    "requestUrlQuery":"192.168.36.163:8088/test1",\n' +
              '    "httpQuote":"192.168.36.163:8088",\n' +
              '    "responseCode":"200",\n' +
              '    "responseMsg":"{\\"code\\":\\"200\\"}",\n' +
              '    "sourceUsername":"hdhhhhdhd测试",\n' +
              '    "sensitiveType":"机密/涉密",\n' +
              '    "sensitiveDataCount":"2",\n' +
              '    "evidence":"949018974859697139",\n' +
              '    "probeIp":"10.20.48.30",\n' +
              '    "dataFrom":"dscAccountSecurity",\n' +
              '    "attackPort":7777\n' +
              '}'
        },
        client: {
          host: 'https://10.50.2.174/open/api/v1/ds/addSecurityEvent/clientSecurity',
          canshu: '{\n' +
              '    "eventFrom":"AIDLP",\n' +
              '    "discoverFactory":"安恒信息",\n' +
              '    "eventsType":[\n' +
              '        "IP单绯闻绯闻为成为"\n' +
              '    ],\n' +
              '    "eventsThreatSeverity":"commonEvent",\n' +
              '    "attacker":[\n' +
              '        "192.168.36.2"\n' +
              '    ],\n' +
              '    "attackPort":"60080",\n' +
              '    "victim":[\n' +
              '        "2.2.2.2"\n' +
              '    ],\n' +
              '    "destPort":11,\n' +
              '    "transportProtocol":"http",\n' +
              '    "appProtocol":[\n' +
              '        "http"\n' +
              '    ],\n' +
              '    "ruleId":"1002000000000000010",\n' +
              '    "requestBody":"",\n' +
              '    "requestDomain":"192.168.36.163:8088",\n' +
              '    "requestMethod":"POST",\n' +
              '    "clientInfo":"PostmanRuntime/7.29.2",\n' +
              '    "appPotocolVersion":"7.29.2\\r\\nAccept:*/*\\r\\nPostman-Token:3955239a-a295-4408-b534-c30b8005b803\\r\\nHost:192.168.36.163:8088\\r\\nReferer:192.168.36.163:8088\\r\\nAccept-Encoding:gzip,deflate,br\\r\\nConnection:keep-alive\\r\\nContent-Length:19270",\n' +
              '    "requestUrl":"/test1/ajsnDAS/00001",\n' +
              '    "requestUrlQuery":"192.168.36.163:8088/test1",\n' +
              '    "httpQuote":"192.168.36.163:8088",\n' +
              '    "responseCode":"200",\n' +
              '    "responseMsg":"",\n' +
              '    "sourceUsername":"hdhhhhdhd怀扥赛",\n' +
              '    "sensitiveType":"机密/涉密",\n' +
              '    "sensitiveDataCount":"2",\n' +
              '    "evidence":"949018974859697139",\n' +
              '    "probeIp":"10.20.48.30",\n' +
              '    "dataFrom":"dscClientSecurity"\n' +
              '}'
        },
      },
      form: {
        lablename: '',
        region: '',
        name: '',
        Authorization: '',
        canshu: '',
        num: 1,
      },
      tableData: [],
      des: {
        leak: '泄漏风险',
        loophole: '漏洞风险',
        website: '网站风险',
        API: 'API事件',
        Account: '账号事件',
        client: '客户端事件',
      },
      fromrule: {
        name: [
          {required: true, message: '请输入要请求的url', trigger: 'blur'},
        ],
        Authorization: [
          {required: true, message: '请输入要请求的Authorization', trigger: 'blur'},
        ],
        canshu: [
          {required: true, message: '请输入要请求的Authorization', trigger: 'blur'},
          {validator: checkcanshu, trigger: 'blur'}
        ],
      }
    }
  },

  methods: {
    toggleExpanded() {
      this.expanded = !this.expanded
    },
    restoggleExpanded() {
      this.resexpanded = !this.resexpanded
    },
    onSubmit() {
      this.$refs.form.validate(valid => {
        if (!valid) return this.$message.warning('输入的参数不正确')
        this.onRun(this.form)
      })
    },
    async onRun(row) {
      const {data} = await addDataInfo(row)

      if (data.click !== 1) {
        this.$message.error(data.messages)
      } else {
        this.$message.success(data.messages)
      }
      this.getlist()
    },
    changeShijian(data) {
      this.defaultRegion = data
      this.initFrom()
    },
    async getlist() {
      const {data: datalist} = await getDataInfo()
      this.tableData = datalist.data
    },
    initFrom() {
      this.form = {
        lablename: this.des[this.defaultRegion],
        region: this.defaultRegion,
        name: this.defaultInfo[this.defaultRegion].host,
        Authorization: '',
        canshu: this.defaultInfo[this.defaultRegion].canshu,
        sum: 1,
      }
    }
  },
  created() {
    this.initFrom()
    this.getlist()
  },
}
</script>
<style lang="less" scoped>
.home {
  margin: 0;
  padding: 0;
  width: 80%;
  position: absolute;
  left: 50%;
  transform: translate(-50%,);


  .el-form {
    font-weight: bold;

    .el-form-item {
      margin: 20px 30px;

      /deep/ .el-form-item__label {
        font-size: 12px;
      }

      ///deep/ .el-form-item__error {
      //  font-weight: bold;
      //}

      /deep/ .el-form-item.is-error .el-input__inner {
        border-color: blue;
      }

      /deep/ .el-form-item.is-error .el-input__validateIcon {
        color: blue;
      }

      /deep/ .el-form-item__error {
        color: blue;
      }
    }

    .el-input-number {
      position: absolute;
      left: 0;
    }

    .el-select {
      width: 30%;
      position: absolute;
      left: 0;
    }
  }

  .el-card {
    background: linear-gradient(to right, rgba(234, 239, 238, 0.73), rgb(20, 36, 98));
    margin: 0 2%;
    height: 100%;

    .el-table {
      margin-top: 20px;
      font-size: 8px;

    }
  }

}

</style>
